var waibu = function() {
  /*这里是登录注册页面的左右移动*/
  var loginBtn = document.getElementsByClassName("loginBtn")[0];
  var loginBtnContainer = document.getElementsByClassName(
    "loginBtnContainer"
  )[0];
  var handoverLogin = document.getElementsByClassName("handoverLogin")[0];
  var singBtnContainer = document.getElementsByClassName("singBtnContainer")[0];
  var handoverSign = document.getElementsByClassName("handoverSign")[0];
  var signBtn = document.getElementsByClassName("signBtn")[0];
  loginBtn.onclick = function() {
    loginBtnContainer.style.left = "100%";
    handoverSign.style.right = "100%";
    setTimeout(function() {
      handoverLogin.style.left = "0";
      singBtnContainer.style.right = "0";
    }, 300);
  };
  signBtn.onclick = function() {
    handoverLogin.style.left = "100%";
    singBtnContainer.style.right = "100%";
    setTimeout(function() {
      loginBtnContainer.style.left = "0";
      handoverSign.style.right = "0";
    }, 300);
  };
  /*随机数做验证码*/
  var comple = document.getElementsByClassName("comple")[0];
  var random;
  function num() {
    random = Math.floor(Math.random() * 9000 + 1000);
    comple.innerHTML = random;
  }
  num();
  comple.onclick = function() {
    num();
  };
  /*隐私协议*/
  var privacyInput = document.getElementsByClassName("privacyInput")[0];
  var sign_btn = document.getElementsByClassName("sign_btn")[0];
  let signTrue = document.getElementsByClassName("signTrue")[0];
  sign_btn.style.backgroundColor = "#8d9299";
  privacyInput.onclick = function() {
    if (privacyInput.checked == true) {
      sign_btn.style.backgroundColor = "";
      sign_btn.style.cursor = "pointer";
      sign_btn.onclick = function() {
        if (signTrue.value !== comple.innerHTML) {
          Tips("验证码不正确");
        } else if (signpassword[0].value !== signpassword[1].value) {
          signpassword[0].style.border = "1px solid red";
          signpassword[1].style.border = "1px solid red";
          Tips("两次密码不一致");
        }
      };
    } else {
      sign_btn.style.backgroundColor = "#8d9299";
      sign_btn.style.cursor = "no-drop";
      sign_btn.onclick = function() {};
    }
  };

  /*其他登录方式*/
  let cutLogin = document.getElementsByClassName("cutLogin")[0];
  let emailLogin = document.getElementsByClassName("emailLogin")[0];
  let loginInputContainer = document.getElementsByClassName(
    "loginInputContainer"
  )[0];
  let returnLoginEmail = document.getElementsByClassName("returnLoginEmail")[0];
  cutLogin.onclick = function() {
    emailLogin.style.display = "block";
    loginInputContainer.style.display = "none";
  };
  returnLoginEmail.onclick = function() {
    emailLogin.style.display = "none";
    loginInputContainer.style.display = "block";
  };
  /*其他方式注册*/
  let cut = document.getElementsByClassName("cut")[0];
  let signEmail = document.getElementsByClassName("signEmail")[0];
  let signInputContainer = document.getElementsByClassName(
    "signInputContainer"
  )[0];
  let returnSignEmail = document.getElementsByClassName("returnSignEmail")[0];
  cut.onclick = function() {
    signInputContainer.style.display = "none";
    signEmail.style.display = "block";
  };
  returnSignEmail.onclick = function() {
    signInputContainer.style.display = "block";
    signEmail.style.display = "none";
  };
  /*其他方式注册*/
  /*邮箱输入框*/
  let emailLoginInputText = document.getElementsByClassName(
    "emailLoginInputText"
  )[0];
  /*点击获取验证码*/
  let valiBtn = document.getElementsByClassName("valiBtn");
  /*验证码输入框*/
  let identifyingInput = document.getElementsByClassName("identifyingInput")[0];
  /*密码*/
  let identifyingPasswordInput = document.getElementsByClassName(
    "identifyingPasswordInput"
  );
  let QQ = /^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  var email = null;
  let emailLoginBtn = document.getElementsByClassName("emailLoginBtn");
  valiBtn[1].onclick = function() {
    if (!QQ.test(emailLoginInputText.value)) {
      Tips("邮箱格式不正确");
      emailLoginInputText.style.border = "1px solid red";
    } else {
      email = emailLoginInputText.value;
    }
  };
  JudgeQQ();
  function JudgeQQ() {
    emailLoginBtn[1].onclick = function() {
      if (emailLoginInputText.value === "") {
        Tips("请输入QQ邮箱");
      } else if (identifyingInput.value === "") {
        Tips("请输入验证码");
      } else if (identifyingPasswordInput[0] === "") {
        /*判断密码是否为空*/
        Tips("密码不能为空");
        identifyingPasswordInput[0].style.border = "1px solid red";
      } else if (identifyingPasswordInput[1] === "") {
        /*判断二次密码是否为空*/
        Tips("第二次密码不能为空");
        identifyingPasswordInput[1].style.border = "1px solid red";
      } else if (
        !(
          identifyingPasswordInput[0].value.length >= 8 &&
          identifyingPasswordInput[0].value.length <= 12
        )
      ) {
        Tips("密码长度应为8~12位");
      } else if (
        identifyingPasswordInput[0].value !== identifyingPasswordInput[1].value
      ) {
        Tips("两次密码不一样");
        identifyingPasswordInput[0].style.border = "1px solid red";
        identifyingPasswordInput[1].style.border = "1px solid red";
      }
    };
  }
  emailLoginInputText.onfocus = function() {
    emailLoginInputText.style.border = "";
  };
  for (let i = 0; i < 2; i++) {
    identifyingPasswordInput[i].onfocus = function() {
      identifyingPasswordInput[0].style.border = "";
      identifyingPasswordInput[1].style.border = "";
    };
  }
  /*其他方式登录*/
  /*邮箱登录输入框*/
  let emailLoginInputTextT = document.getElementsByClassName(
    "emailLoginInputTextT"
  )[0];
  /*验证码输入框*/
  let VerificationCode = document.getElementsByClassName("VerificationCode")[0];

  valiBtn[0].onclick = function() {
    if (!QQ.test(emailLoginInputTextT.value)) {
      Tips("邮箱格式不正确");
    }
  };
  function emailLoginT() {
    emailLoginBtn[0].onclick = function() {
      if (emailLoginInputTextT.value == "") {
        Tips("请输入QQ邮箱号");
      } else if (VerificationCode == "") {
        Tips("请输入验证码");
      }
    };
  }
  let userName = document.getElementsByClassName("userName")[0];
  let password = document.getElementsByClassName("password")[0];
  let login_btn = document.getElementsByClassName("login_btn")[0];
  let error = document.getElementsByClassName("error");
  let tips = document.getElementsByClassName("tips")[0];
  /*登录*/

  /*注册*/
  var signuserName = document.getElementsByClassName("signuserName")[0];
  var signpassword = document.getElementsByClassName("signpassword");

  signpassword[0].onfocus = function() {
    signpassword[0].style.border = "";
    signpassword[1].style.border = "";
  };
  signpassword[1].onfocus = function() {
    signpassword[0].style.border = "";
    signpassword[1].style.border = "";
  };
  function Tips(i) {
    tips.innerHTML = i;
    tips.style.top = "56px";
    let timer = setTimeout(function() {
      tips.style.top = "-56px";
      clearTimeout(timer);
    }, 1000);
  }
};

export {waibu}
